package com.example.myapplication.tack_25;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.R;
import com.example.myapplication.tack_18.InspectionActivity;
import com.example.myapplication.utils.DistrictTool;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TrafficManagementActivity extends AppCompatActivity {
    private ImageView exit;
    private TextView carType;
    private List<String> listKey;
    private TextView submit;
    final String[] options = {"小型汽车", "大型汽车", "小型新能源","大型新能源"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_25_activity_traffic_management);
        init();
        exit_();
        initSpinner();
        initCarType();
        initSubmit();
    }

    private void initSubmit() {
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TrafficManagementActivity.this,"暂无车辆违章信息",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initCarType() {
        carType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(TrafficManagementActivity.this);
                View view = getLayoutInflater().inflate(R.layout.tack_25_plateno,null);
                builder.setView(view);
                increase(view,builder);
            }
        });
    }

    private void initSpinner() {
        Map<String, String> map = DistrictTool.addDistrict();
        Set<String>  key = map.keySet();
        for (String s : key) {
            listKey.add(s);
        }
        ArrayAdapter<String> starAdapter = new ArrayAdapter<String>(TrafficManagementActivity.this, R.layout.tack_25_item_select,listKey);
        starAdapter.setDropDownViewResource(R.layout.tack_25_item_dropdown);
        Spinner sp = findViewById(R.id.spinner);
        sp.setAdapter(starAdapter);
        sp.setSelection(0);

    }



    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TrafficManagementActivity.this.finish();
            }
        });
    }

    private void init() {

        exit = findViewById(R.id.exit);
        submit = findViewById(R.id.submit);
        carType = findViewById(R.id.carType);
        listKey = new ArrayList();
    }

    private void increase(View view, AlertDialog.Builder builder) {
        builder.setCancelable(false).setNegativeButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                RadioGroup radio = view.findViewById(R.id.radio);
                int checkedRadioButtonId = radio.getCheckedRadioButtonId();
                if(checkedRadioButtonId % 100 == 38){
                    carType.setText("小型汽车");
                }
                if(checkedRadioButtonId % 100 == 39){
                    carType.setText("大型汽车");
                }
                if(checkedRadioButtonId % 100 == 40){
                    carType.setText("小型新能源");
                }
                if(checkedRadioButtonId % 100 == 41){
                    carType.setText("大型新能源");
                }
                if(checkedRadioButtonId % 100 == 42){
                    carType.setText("摩托车");
                }
            }
        });
        builder.show();
    }
}